<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <script type="text/javascript" src="/static/plugins/layui/layui.js"></script>
	<style type="text/css">
		.header span{
			background:#009680; 
			font-size: 18px;
			margin-left: 10px;
			padding: 5px;
		}
	</style>
</head>
<body style="padding: 10px;">
	<div class="header">
		<span>菜单管理</span>
		<hr style="border: solid 1px;">
	</div>
	<form class="layui-form" >
		{if condition="$pid>0"}
		<button class="layui-btn layui-btn-primary layui-btn-sm" style="float: right;margin:5px 0px;" onclick="back({$backid});return false;">返回上级</button>
		{/if}

		<input type="hidden" name="pid" value="{$pid}">

	<table class="layui-table">
		<thead>
			<tr>
				<th>ID</th>
				<th>排序</th>
				<th>菜单名称</th>
				<th>controller</th>
				<th>method</th>
				<th>是否隐藏</th>
				<th>是否禁用</th>
				<th></th>
			</tr>
		</thead>
		<tbody>
			{volist name="data.lists" id="vo"}
			<tr>
				<td>{$vo.mid}</td>
				<td><input type="text" name="ord[{$vo.mid}]" class="layui-input" value="{$vo.ord}"></td>
				<td><input type="text" name="title[{$vo.mid}]" class="layui-input" value="{$vo.title}"></td>
				<td><input type="text" name="controller[{$vo.mid}]" class="layui-input" value="{$vo.controller}"></td>
				<td><input type="text" name="method[{$vo.mid}]" class="layui-input" value="{$vo.method}"></td>
				<td>
					<input type="checkbox" name="ishidden[{$vo.mid}]" lay-skin="primary" title="隐藏"
					 {$vo.ishidden?'checked':''} value=1>
				</td>
				<td>
					<input type="checkbox" name="status[{$vo.mid}]" lay-skin="primary" title="禁用" 
					{$vo.status?'checked':''} value=1>
				</td>
				<td>
					{if condition="$pid==0"}
					<button class="layui-btn layui-btn-xs" onclick="child({$vo.mid});return false;">子菜单</button>
					{/if}
				</td>
			</tr>
			{/volist}

			<tr>
				<td></td>
				<td><input type="text" name="ord[0]" class="layui-input" value=""></td>
				<td><input type="text" name="title[0]" class="layui-input" value=""></td>
				<td><input type="text" name="controller[0]" class="layui-input" value=""></td>
				<td><input type="text" name="method[0]" class="layui-input" value=""></td>
				<td>
					<input type="checkbox" name="ishidden[0]" lay-skin="primary" title="隐藏"
					  value=1>
				</td>
				<td>
					<input type="checkbox" name="status[0]" lay-skin="primary" title="禁用" 
					 value=1>
				</td>
				<td></td>
			</tr>
		</tbody>
	</table>
	</form>
	<button class="layui-btn" onclick="save()">保存</button>


<script type="text/javascript">
		layui.use(['layer','form'],function(){
		layer=layui.layer;
		form=layui.form;
		$=layui.jquery;
	});	

    //子菜单
	function child(pid){
		window.location.href='/admins.php/admins/Menu/index?pid='+pid;
	}

	//返回上级
	function back(pid){
		window.location.href='/admins.php/admins/Menu/index?pid='+pid;

	}

	//保存，编辑删除添加
	function save(){
		$.post('/admins.php/admins/Menu/save',$('form').serialize(),function(res){
			if(res.code>0){
					layer.alert(res.msg,{'icon':2});
				}else{
					layer.msg(res.msg);
					setTimeout(function(){window.location.reload();},1000);
				}
		},'json');

	}
</script>
	
</body>
</html>
